See Also

Udp Class  | Udp Members  | Overload List

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Language

Visual Basic

C#

C++

C++/CLI

Show All

buffer
A byte array to be filled with the data received.
offset
Starting offset within buffer for filling.
count
Maximum number of bytes to receive.
socketFlags
A bitwise combination of special use receiving parameters.
See Also Languages PowerTCP SSL Sockets for .NET

Receive(Byte[],Int32,Int32,SocketFlags) Method

Dart.PowerTCP.SslSockets Namespace > Udp Class > Receive Method : Receive(Byte[],Int32,Int32,SocketFlags) Method

Receive a datagram, specifying a buffer, offset, length and SocketFlags value.

[Visual Basic]
<DescriptionAttribute("Receive a datagram into your buffer.")> Overloads Public Function Receive( _    ByVal buffer() As Byte, _    ByVal offset As Integer, _    ByVal count As Integer, _    ByVal socketFlags As SocketFlags _ ) As Datagram
[C#]
[DescriptionAttribute("Receive a datagram into your buffer.")] public Datagram Receive(    byte[] buffer,    int offset,    int count,    SocketFlags socketFlags );
[C++]
[DescriptionAttribute("Receive a datagram into your buffer.")] public: Datagram* Receive(    byte[]* buffer,    int offset,    int count,    SocketFlags socketFlags )
[C++/CLI]
[DescriptionAttribute("Receive a datagram into your buffer.")] public: Datagram^ Receive(    bytearray<buffer>^ buffer,    int offset,    int count,    SocketFlags socketFlags )

Parameters

buffer
A byte array to be filled with the data received.
offset
Starting offset within buffer for filling.
count
Maximum number of bytes to receive.
socketFlags
A bitwise combination of special use receiving parameters.

Return Type

A Datagram object encapsulating the datagram received.

Exceptions

ExceptionDescription
ArgumentNullExceptionbuffer is null.
ArgumentOutOfRangeExceptionoffset or count is less than 0.
ArgumentExceptionoffset + count is greater than the length of buffer.

Remarks

Use the Udp.Receive method to receive a datagram into buffer after first calling Open to specify a port/address to listen for datagrams. This method also returns a Datagram object encapsulating the datagram received. Buffer contains the actual datagram data (equivalent to buffer). RemoteEndPoint contains the address/port of the remote host from which the datagram was sent.

A UDP datagram provides little functionality over an IP datagram, adding a port number field which allows multiplexing on the receiving host and checksum field which provides basic error handling. Unlike TCP, UDP datagrams are sent as a unit. If Send is called 3 times to send 3 datagrams to a host, the receiving host will have to call Udp.Receive 3 times. Also, the size of each datagram sent will equal the size of each datagram received by the receiving host. In addition, since UDP is a connectionless protocol, any datagrams sent to the host are not guaranteed to be delivered. Therefore, any required error checking (outside of UDP's checksum implementation) will have to be done by the application-layer protocol.

Example

The following example demonstrates...

[Visual Basic] 

' Begin listening on the specified port and address
Udp1.Open("MyHostName", 8888)

' Send a broadcast to all hosts on the network on port 8888
Udp1.Send("hello everyone", "255.255.255.255", "8888")

' Receive the broadcast datagram.
Dim buffer(Udp1.BufferSize) As Byte
Debug.WriteLine(System.Text.Encoding.Default.GetString(buffer))

' Display data
Debug.WriteLine(d.ToString())

'* Output
'* ---------------------
'* hello everyone
'* ---------------------
'*

[C#] 


// Begin listening on the specified port and address
udp1.Open("MyHostName", 8888);

// Send a broadcast to all hosts on the network on port 8888
udp1.Send("hello everyone", "255.255.255.255", "8888");

// Receive the broadcast datagram.
byte[] buffer = new byte[udp1.BufferSize];
udp1.Receive(buffer);

// Display data
Debug.WriteLine(System.Text.Encoding.Default.GetString(buffer));

/* Output
* ---------------------
* hello everyone
* ---------------------
*/
                

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

Udp Class  | Udp Members  | Overload List


Send comments on this topic.

Documentation version 1.1.2.0.

© 2008 Dart Communications.  All rights reserved.